package com.miracle9.game.dao;
import com.miracle9.game.entity.JoyDesk;
import java.util.List;
import org.hibernate.Query;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Repository;

@Repository
public class JoyDeskServiceDao extends SqlOperating<JoyDesk, Integer>
{
  @Caching(evict={@CacheEvict(value={"springCache"}, key="'getAllJoyDesk'")})
  public void voidMethod() {}
  
  @Cacheable(value={"springCache"}, key="'getAllJoyDesk'")
  public List<JoyDesk> getJoyDesks()
  {
    return q_CreateSqlList("from JoyDesk order by id ", new Object[0]);
  }
  
  @CacheEvict(value={"springCache"}, key="'getAllJoyDesk'")
  public void UpdateSumIfById(int id)
  {
    if (id == -1) {
    	q_CreateSql("update JoyDesk set sumYaFen=0,sumDeFen=0", new Object[0]).executeUpdate();
    } else {
    	q_CreateSql("update JoyDesk set sumYaFen=0,sumDeFen=0 where id=?", new Object[] { Integer.valueOf(id) }).executeUpdate();
    }
  }
  
  @CacheEvict(value={"springCache"}, key="'getAllJoyDesk'")
  public void save(JoyDesk joyDesk)
  {
    update(joyDesk);
  }
  
  @CacheEvict(value={"springCache"}, key="'getAllJoyDesk'")
  public void updateOrderByById(int id, int index)
  {
	  q_CreateSql("update JoyDesk set orderBy=? where id=?", new Object[] { Integer.valueOf(index), Integer.valueOf(id) }).executeUpdate();
  }
  
  public void updateStateByById(int id, int state)
  {
	  q_CreateSql("update JoyDesk set state=? where id=?", new Object[] { Integer.valueOf(state), Integer.valueOf(id) }).executeUpdate();
  }
  
  public int getQuantityByModeId(int nModeId)
  {
    return q_CreateSqlInt("select count(*) from JoyDesk where modeId = ?", new Object[] {
      Integer.valueOf(nModeId) });
  }
}
